import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-01-10
 * Time:20:38
 */
class Solution {
    public boolean isValid(String s) {
        Stack stack=new Stack<Character>();
        for(int i=0;i<s.length();i++){
            char a=s.charAt(i);
            if((a=='(')||(a=='{')||(a=='[')){
                stack.push(a);
            }else{
                if(stack.empty()){
                    return false;
                }
                if(a==')'&&stack.peek().equals('(')){
                    stack.pop();
                }else if(a=='}'&&stack.peek().equals('{')){
                    stack.pop();
                }else if(a==']'&&stack.peek().equals('[')){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }
        if(stack.empty()){
            return true;
        }
        return false;
    }
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        int pusha=0;
        int popa=0;
        Stack<Integer> stack1=new Stack <>();
        while(pusha<pushA.length){
            stack1.push(pushA[pusha++]);
            while(!stack1.empty()&&stack1.peek()==popA[popa]){
                stack1.pop();
                popa++;
            }



        }
        if(popa==popA.length){
            return true;
        }
        return false;
    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        int sum=0;

        for(int i=0;i<tokens.length;i++){
            String a=tokens[i];
            if(a.equals( "+")||a.equals("/")||a.equals("*")||a.equals("-")){
                int b=stack.pop();
                int c=stack.pop();
                switch(a)
                {
                    case "+":
                        sum=c+b;
                        stack.push(sum);
                        break;
                    case "-":
                        sum=c-b;
                        stack.push(sum);
                        break;
                    case "*":
                        sum=c*b;
                        stack.push(sum);
                        break;
                    case "/":
                        sum=c/b;
                        stack.push(sum);
                        break;
                }
            }else{
                stack.push(Integer.parseInt(a));
            }
        }
        return stack.pop();
    }
}
public class Test {
}
